package cn.bdqn.common;




import cn.bdqn.pojo.Users;


import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ValidationToken {

    @Resource
    private RedisAPI redisAPI;

    public Users getCurrentUser(String tokenString) {
        //根据token从redis中获取用户信息
        Users user = null;
        if (null == tokenString || "".equals(tokenString)) {
            return null;
        }
        try {
            String userInfoJson = redisAPI.get(tokenString);
            user = JSONObject.parseObject(userInfoJson, Users.class);
        } catch (Exception e) {
            user = null;
        }
        return user;
    }
}
